﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="contact-add.aspx.cs" Inherits="VQWEB.administrator.contact.contact_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
   <form id="frmObjects" action="" method="post">
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
<script type="text/javascript">
    ShowToolBar("edit");
    var url_ashx = "/admin/contact/handler";
    var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

    $(document).ready(function () {
        if (CheckAtionInPath("add")) {
            loadform(0, "", "","","","","", false);
        }
        else if (CheckAtionInPath("edit")) {
            $.get(url_ashx, { view_contact: "view_contact", Id: GetId() }, function (data) {
                var obj = $.parseJSON(data);
                loadform(obj.id, obj.address,obj.fullname,obj.phone,obj.email, obj.content,obj.date, obj.active);
            });
        }

    });

    function loadform(id, address, fullname,phone,email,content,date, active) {
        $.jqoteload(url_input, function (tmpl) {

            $("#frmObjects").single("hidden", "contact_id", id, null, null, tmpl.input_tpl);
            $("#frmObjects").single("text", "contact_fullname", fullname, "Họ Tên:", null, tmpl.input_tpl);
            $("#frmObjects").single("text", "contact_phone", phone, "Điện thoại:", null, tmpl.input_tpl);
            $("#frmObjects").single("text", "contact_email", email, "Email:", null, tmpl.input_tpl);
            $("#frmObjects").single("text", "contact_address", address, "Địa chỉ:", null, tmpl.input_tpl);
            $("#frmObjects").single("editor", "contact_content", content, "Nội dung:", null, tmpl.input_tpl);
            $("#frmObjects").single("text", "contact_date", date, "Thời gian:", null, tmpl.input_tpl);
            $("#frmObjects").single("checkbox", "contact_active", true, "Kich hoat", active, tmpl.input_tpl);
            tinymce.init({ selector: 'textarea#tinymce' });
            $("#frmObjects").validate({
                rules: { contact_fullname: { required: true }, contact_email: { required: true }, contact_phone: { required: true }, contact_address: {required: true} },
                messages: { contact_fullname: { required: null }, contact_email: { required: null }, contact_phone: { required: null }, contact_address: { required: true} }
            });
            $("input[name='contact_phone']").mask("(999) 99-9999");
            $("input[name='contact_date']").mask("99/99/9999");
        });

    }

   
    $(document).on("click", "#btnCancel", function () {
        window.location = "/admin/contact/list";
    });
    $(document).on("click", "#btnSave", function () {
        if ($("#frmObjects").valid()) {
            var value = tinymce.get('tinymce').getContent();
            $("textarea[name='contact_content']").val(value);
            var arr = $("#frmObjects").serializeObject();
            $.post(url_ashx, { add_contact: window.escape(arr) }, function (data) {
                alert(data);
                window.location = "/admin/contact/list";
            });
        }
    });
    </script>
</asp:Content>
